package inno.data;

import java.util.HashMap;

public class MovingAvgSingelton {
	private static MovingAvgSingelton instance = new MovingAvgSingelton();
	private int stocksSum;
	private String stocksNames[];
	private DataReaderSingelton stocksData;
	
	private HashMap<String, MovingAvg> MovingAvgHashMap;
	
	private MovingAvgSingelton() {
    }
 
    public static synchronized MovingAvgSingelton getInstance() {
        return instance;
    }
    
    
 
    public void initialize(int stocksSum, String stocksNames[], int[] bumps, int bumpsNum) {
    	this.stocksNames = stocksNames;
    	this.stocksSum = stocksSum;
    	this.stocksData = DataReaderSingelton.getInstance();
    	MovingAvgHashMap = new HashMap<String, MovingAvg>();
        for (int i=0; i<stocksSum; i++) {
        	MovingAvg myMovingAvg = new MovingAvg(stocksData.getAllClosingPrice(stocksNames[i]), bumps, bumpsNum);
        	MovingAvgHashMap.put(stocksNames[i], myMovingAvg);
        }
    }
    
    public MovingAvg getStockMovingAvg(String stockName){
    	return MovingAvgHashMap.get(stockName);
    }
 
    @Override
    protected Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException("Clone is not allowed.");
    }

}
